home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Bank smakow / BankSmakow.air / BankSmakow.swf / scripts / mx / controls / treeClasses / DefaultDataDescriptor.as next >
Text File  |  2009-12-16  |  13KB  |  472 lines

  1. package mx.controls.treeClasses
  2. {
  3.    import flash.utils.Dictionary;
  4.    import mx.collections.ArrayCollection;
  5.    import mx.collections.CursorBookmark;
  6.    import mx.collections.ICollectionView;
  7.    import mx.collections.IList;
  8.    import mx.collections.IViewCursor;
  9.    import mx.collections.XMLListCollection;
  10.    import mx.controls.menuClasses.IMenuDataDescriptor;
  11.    import mx.core.mx_internal;
  12.    
  13.    use namespace mx_internal;
  14.    
  15.    public class DefaultDataDescriptor implements ITreeDataDescriptor2, IMenuDataDescriptor
  16.    {
  17.       
  18.       mx_internal static const VERSION:String = "3.5.0.12683";
  19.        
  20.       
  21.       private var ChildCollectionCache:Dictionary;
  22.       
  23.       public function DefaultDataDescriptor()
  24.       {
  25.          ChildCollectionCache = new Dictionary(true);
  26.          super();
  27.       }
  28.       
  29.       public function setEnabled(param1:Object, param2:Boolean) : void
  30.       {
  31.          var node:Object = param1;
  32.          var value:Boolean = param2;
  33.          if(node is XML)
  34.          {
  35.             node.@enabled = value;
  36.          }
  37.          else if(node is Object)
  38.          {
  39.             try
  40.             {
  41.                node.enabled = value;
  42.             }
  43.             catch(e:Error)
  44.             {
  45.             }
  46.          }
  47.       }
  48.       
  49.       public function removeChildAt(param1:Object, param2:Object, param3:int, param4:Object = null) : Boolean
  50.       {
  51.          var cursor:IViewCursor = null;
  52.          var children:ICollectionView = null;
  53.          var parent:Object = param1;
  54.          var child:Object = param2;
  55.          var index:int = param3;
  56.          var model:Object = param4;
  57.          if(!parent)
  58.          {
  59.             try
  60.             {
  61.                if(index > model.length)
  62.                {
  63.                   index = model.length;
  64.                }
  65.                if(model is IList)
  66.                {
  67.                   model.removeItemAt(index);
  68.                }
  69.                else
  70.                {
  71.                   cursor = model.createCursor();
  72.                   cursor.seek(CursorBookmark.FIRST,index);
  73.                   cursor.remove();
  74.                }
  75.                return true;
  76.             }
  77.             catch(e:Error)
  78.             {
  79.             }
  80.          }
  81.          else
  82.          {
  83.             children = ICollectionView(getChildren(parent,model));
  84.             try
  85.             {
  86.                if(index > children.length)
  87.                {
  88.                   index = children.length;
  89.                }
  90.                if(children is IList)
  91.                {
  92.                   IList(children).removeItemAt(index);
  93.                }
  94.                else
  95.                {
  96.                   cursor = children.createCursor();
  97.                   cursor.seek(CursorBookmark.FIRST,index);
  98.                   cursor.remove();
  99.                }
  100.                return true;
  101.             }
  102.             catch(e:Error)
  103.             {
  104.             }
  105.          }
  106.          return false;
  107.       }
  108.       
  109.       public function isToggled(param1:Object) : Boolean
  110.       {
  111.          var toggled:* = undefined;
  112.          var node:Object = param1;
  113.          if(node is XML)
  114.          {
  115.             toggled = node.@toggled;
  116.             if(toggled[0] == true)
  117.             {
  118.                return true;
  119.             }
  120.          }
  121.          else if(node is Object)
  122.          {
  123.             try
  124.             {
  125.                return Boolean(node.toggled);
  126.             }
  127.             catch(e:Error)
  128.             {
  129.             }
  130.          }
  131.          return false;
  132.       }
  133.       
  134.       public function getHierarchicalCollectionAdaptor(param1:ICollectionView, param2:Function, param3:Object, param4:Object = null) : ICollectionView
  135.       {
  136.          return new HierarchicalCollectionView(param1,this,param2,param3);
  137.       }
  138.       
  139.       public function addChildAt(param1:Object, param2:Object, param3:int, param4:Object = null) : Boolean
  140.       {
  141.          var cursor:IViewCursor = null;
  142.          var children:ICollectionView = null;
  143.          var temp:XMLList = null;
  144.          var parent:Object = param1;
  145.          var newChild:Object = param2;
  146.          var index:int = param3;
  147.          var model:Object = param4;
  148.          if(!parent)
  149.          {
  150.             try
  151.             {
  152.                if(index > model.length)
  153.                {
  154.                   index = model.length;
  155.                }
  156.                if(model is IList)
  157.                {
  158.                   IList(model).addItemAt(newChild,index);
  159.                }
  160.                else
  161.                {
  162.                   cursor = model.createCursor();
  163.                   cursor.seek(CursorBookmark.FIRST,index);
  164.                   cursor.insert(newChild);
  165.                }
  166.                return true;
  167.             }
  168.             catch(e:Error)
  169.             {
  170.             }
  171.          }
  172.          else
  173.          {
  174.             children = ICollectionView(getChildren(parent,model));
  175.             if(!children)
  176.             {
  177.                if(parent is XML)
  178.                {
  179.                   temp = new XMLList();
  180.                   XML(parent).appendChild(temp);
  181.                   children = new XMLListCollection(parent.children());
  182.                }
  183.                else if(parent is Object)
  184.                {
  185.                   parent.children = new ArrayCollection();
  186.                   children = parent.children;
  187.                }
  188.             }
  189.             try
  190.             {
  191.                if(index > children.length)
  192.                {
  193.                   index = children.length;
  194.                }
  195.                if(children is IList)
  196.                {
  197.                   IList(children).addItemAt(newChild,index);
  198.                }
  199.                else
  200.                {
  201.                   cursor = children.createCursor();
  202.                   cursor.seek(CursorBookmark.FIRST,index);
  203.                   cursor.insert(newChild);
  204.                }
  205.                return true;
  206.             }
  207.             catch(e:Error)
  208.             {
  209.             }
  210.          }
  211.          return false;
  212.       }
  213.       
  214.       public function getData(param1:Object, param2:Object = null) : Object
  215.       {
  216.          return Object(param1);
  217.       }
  218.       
  219.       public function setToggled(param1:Object, param2:Boolean) : void
  220.       {
  221.          var node:Object = param1;
  222.          var value:Boolean = param2;
  223.          if(node is XML)
  224.          {
  225.             node.@toggled = value;
  226.          }
  227.          else if(node is Object)
  228.          {
  229.             try
  230.             {
  231.                node.toggled = value;
  232.             }
  233.             catch(e:Error)
  234.             {
  235.             }
  236.          }
  237.       }
  238.       
  239.       public function getNodeDepth(param1:Object, param2:IViewCursor, param3:Object = null) : int
  240.       {
  241.          if(param1 == param2.current)
  242.          {
  243.             return HierarchicalViewCursor(param2).currentDepth;
  244.          }
  245.          return -1;
  246.       }
  247.       
  248.       public function getType(param1:Object) : String
  249.       {
  250.          var node:Object = param1;
  251.          if(node is XML)
  252.          {
  253.             return String(node.@type);
  254.          }
  255.          if(node is Object)
  256.          {
  257.             try
  258.             {
  259.                return String(node.type);
  260.             }
  261.             catch(e:Error)
  262.             {
  263.             }
  264.          }
  265.          return "";
  266.       }
  267.       
  268.       public function getGroupName(param1:Object) : String
  269.       {
  270.          var node:Object = param1;
  271.          if(node is XML)
  272.          {
  273.             return node.@groupName;
  274.          }
  275.          if(node is Object)
  276.          {
  277.             try
  278.             {
  279.                return node.groupName;
  280.             }
  281.             catch(e:Error)
  282.             {
  283.             }
  284.          }
  285.          return "";
  286.       }
  287.       
  288.       public function getParent(param1:Object, param2:ICollectionView, param3:Object = null) : Object
  289.       {
  290.          return HierarchicalCollectionView(param2).getParentItem(param1);
  291.       }
  292.       
  293.       public function hasChildren(param1:Object, param2:Object = null) : Boolean
  294.       {
  295.          var node:Object = param1;
  296.          var model:Object = param2;
  297.          if(node == null)
  298.          {
  299.             return false;
  300.          }
  301.          var children:ICollectionView = getChildren(node,model);
  302.          try
  303.          {
  304.             if(children.length > 0)
  305.             {
  306.                return true;
  307.             }
  308.          }
  309.          catch(e:Error)
  310.          {
  311.          }
  312.          return false;
  313.       }
  314.       
  315.       public function isBranch(param1:Object, param2:Object = null) : Boolean
  316.       {
  317.          var childList:XMLList = null;
  318.          var branchFlag:XMLList = null;
  319.          var node:Object = param1;
  320.          var model:Object = param2;
  321.          if(node == null)
  322.          {
  323.             return false;
  324.          }
  325.          var branch:Boolean = false;
  326.          if(node is XML)
  327.          {
  328.             childList = node.children();
  329.             branchFlag = node.@isBranch;
  330.             if(branchFlag.length() == 1)
  331.             {
  332.                if(branchFlag[0] == "true")
  333.                {
  334.                   branch = true;
  335.                }
  336.             }
  337.             else if(childList.length() != 0)
  338.             {
  339.                branch = true;
  340.             }
  341.          }
  342.          else if(node is Object)
  343.          {
  344.             try
  345.             {
  346.                if(node.children != undefined)
  347.                {
  348.                   branch = true;
  349.                }
  350.             }
  351.             catch(e:Error)
  352.             {
  353.             }
  354.          }
  355.          return branch;
  356.       }
  357.       
  358.       public function getChildren(param1:Object, param2:Object = null) : ICollectionView
  359.       {
  360.          var children:* = undefined;
  361.          var childrenCollection:ICollectionView = null;
  362.          var oldArrayCollection:ArrayCollection = null;
  363.          var oldXMLCollection:XMLListCollection = null;
  364.          var p:* = undefined;
  365.          var childArray:Array = null;
  366.          var node:Object = param1;
  367.          var model:Object = param2;
  368.          if(node == null)
  369.          {
  370.             return null;
  371.          }
  372.          if(node is XML)
  373.          {
  374.             children = node.*;
  375.          }
  376.          else if(node is Object)
  377.          {
  378.             try
  379.             {
  380.                children = node.children;
  381.             }
  382.             catch(e:Error)
  383.             {
  384.             }
  385.          }
  386.          if(children == undefined && !(children is XMLList))
  387.          {
  388.             return null;
  389.          }
  390.          if(children is ICollectionView)
  391.          {
  392.             childrenCollection = ICollectionView(children);
  393.          }
  394.          else if(children is Array)
  395.          {
  396.             oldArrayCollection = ChildCollectionCache[node];
  397.             if(!oldArrayCollection)
  398.             {
  399.                childrenCollection = new ArrayCollection(children);
  400.                ChildCollectionCache[node] = childrenCollection;
  401.             }
  402.             else
  403.             {
  404.                childrenCollection = oldArrayCollection;
  405.                ArrayCollection(childrenCollection).mx_internal::dispatchResetEvent = false;
  406.                ArrayCollection(childrenCollection).source = children;
  407.             }
  408.          }
  409.          else if(children is XMLList)
  410.          {
  411.             oldXMLCollection = ChildCollectionCache[node];
  412.             if(!oldXMLCollection)
  413.             {
  414.                for(p in ChildCollectionCache)
  415.                {
  416.                   if(p === node)
  417.                   {
  418.                      oldXMLCollection = ChildCollectionCache[p];
  419.                      break;
  420.                   }
  421.                }
  422.             }
  423.             if(!oldXMLCollection)
  424.             {
  425.                childrenCollection = new XMLListCollection(children);
  426.                ChildCollectionCache[node] = childrenCollection;
  427.             }
  428.             else
  429.             {
  430.                childrenCollection = oldXMLCollection;
  431.                XMLListCollection(childrenCollection).mx_internal::dispatchResetEvent = false;
  432.                XMLListCollection(childrenCollection).source = children;
  433.             }
  434.          }
  435.          else
  436.          {
  437.             childArray = new Array(children);
  438.             if(childArray != null)
  439.             {
  440.                childrenCollection = new ArrayCollection(childArray);
  441.             }
  442.          }
  443.          return childrenCollection;
  444.       }
  445.       
  446.       public function isEnabled(param1:Object) : Boolean
  447.       {
  448.          var enabled:* = undefined;
  449.          var node:Object = param1;
  450.          if(node is XML)
  451.          {
  452.             enabled = node.@enabled;
  453.             if(enabled[0] == false)
  454.             {
  455.                return false;
  456.             }
  457.          }
  458.          else if(node is Object)
  459.          {
  460.             try
  461.             {
  462.                return "false" != String(node.enabled);
  463.             }
  464.             catch(e:Error)
  465.             {
  466.             }
  467.          }
  468.          return true;
  469.       }
  470.    }
  471. }
  472.